package ch06_container.array;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
public class ArrayOpt {
    @Test
    public void array2list() {
        // 数组转列表
        Integer[] a = {1, 2, 4};
        List<Integer> list = Arrays.asList(a);
        System.out.println(list);
        // 转为字符串
        String join = StringUtils.join(list, ",");
        System.out.println(join);
    }

    @Test
    public void list2array() {
        // 列表转数组
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        Integer[] integers = list.toArray(new Integer[0]);
        System.out.println(Arrays.asList(integers));
        // 转为字符串
        String join = StringUtils.join(integers, ",");
        System.out.println(join);
    }
}
